package com.e3.basdoc.employee.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.employee.model.EmployeeModel;
import com.e3.template.model.TGFFormModel;
import com.e3.template.tgf.TGFTabFormPanel;
import com.extjs.gxt.ui.client.widget.form.Field;

public class EmployeeFormPanel extends TGFTabFormPanel<EmployeeModel> {

	@Override
	public EmployeeModel createModelInstance() {
		return EmployeeHelper.INSTANCE.createModelInstance();
	}

	@Override
	public List<TGFFormModel> getFormModels() {
		List<TGFFormModel> models = new ArrayList<TGFFormModel>(2);
		String[] baseNames = {
				EmployeeModel.ID,EmployeeModel.NAME,EmployeeModel.FORMER_NAME
				,EmployeeModel.GENDER,EmployeeModel.IDCARD_NO,EmployeeModel.BIRTHDAY
				,EmployeeModel.EDUCATION,EmployeeModel.EMAIL,EmployeeModel.HOME_PHONE
				,EmployeeModel.HOME_ADDRESS,EmployeeModel.POSTCODE,EmployeeModel.MOBILE
				,EmployeeModel.WORK_FROM_DATE
				};

		String title = EmployeeMessages.INSTANCE.title_group_baseinfo();
		models.add(createTGFFormModel(0, title, baseNames));

		String[] manageNames = {
				EmployeeModel.CODE,EmployeeModel.CLASSES,EmployeeModel.DEPT
				,EmployeeModel.OFFICE_PHONE,EmployeeModel.ONBOARD_DATE,EmployeeModel.BANK
				,EmployeeModel.BANK_ACCOUNT,EmployeeModel.SKILL_LEVEL,EmployeeModel.RANK
				,EmployeeModel.STATUS,EmployeeModel.QUIT_DATE,EmployeeModel.REMARK
				};
		title = EmployeeMessages.INSTANCE.title_group_mangeinfo();
		models.add(createTGFFormModel(0, title, manageNames));
		
		return models;
	}

	private TGFFormModel createTGFFormModel(int code,String title,String[] fNames){
		List<Field<?>> fields = new ArrayList<Field<?>>(fNames.length);
		for (String fname : fNames) {
			Field<?> field = EmployeeHelper.INSTANCE.createFormField(fname);
			fields.add(field);
		}
		return new TGFFormModel(0, title, fields);
	}

	@Override
	public int getLabelWidth() {
		return 100;
	}
		
}
